import Vue from 'vue'
import VueRouter from 'vue-router'
import demo from "@/views/Demo/demo.vue";
import HomeView from "@/views/HomeView.vue";
import CourseView from "@/views/CourseView.vue";
import courseTypeView from "@/views/CourseTypeView.vue";
import courseListView from "@/views/CourseListView.vue";
import UserSetting from "@/views/UserSetting.vue";
import learnView from "@/views/LearnView.vue";
import announceView from "@/views/AnnounceView.vue";
import ContentView from "@/views/ContentView.vue";
import testListView from "@/views/TestListView.vue";
import forumindexView from "@/views/ForumindexView.vue";
import courseEditListView from "@/views/CourseEditListView.vue";
import addCourseView from "@/views/AddCourseView.vue";
import CourseHomeEditView from "@/views/CourseHomeEditView.vue";
import UserHomeView from "@/views/UserHomeView.vue";
import CourseEditView from "@/views/LearnEditView.vue";
import announceEditView from "@/views/AnnounceEditView.vue";
import ContentEditView from "@/views/ContentEditView.vue";
import testListEditView from "@/views/TestListEditView.vue";
import forumindexEditView from "@/views/ForumindexEditView.vue";
import learnEditView from "@/views/LearnEditView.vue";
import demoWangEditor from "@/views/Demo/DemoWangEditor.vue";
import searchView from "@/views/SearchView.vue";
import schoolListView from "@/views/SchoolListView.vue";
import testScoringView from "@/views/TestScoringView.vue";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/homeView'
  },
  // {
  //   path: '/demo',
  //   name: 'Demo',
  //   component: demo
  // },
  {
    path: '/homeView',
    name: 'HomeView',
    component: HomeView,
    meta: {
      title: '共享课程平台-首页'
    }
  },
  {
    path:'/courseView/:courseId',
    name:'CourseView',
    component: CourseView,
    meta: {
      title: '共享课程平台-课程'
    }
  },
  {
    path:'/schoolList',
    name:'SchoolListView',
    component: schoolListView,
    meta: {
      title: '共享课程平台-合作组织'
    }
  },
  {
    path: '/userSetting',
    name:'UserSetting',
    component: UserSetting,
    meta: {
      title: '共享课程平台-设置'
    }
  },
  {
    path: '/search',
    name: 'SearchView',
    component: searchView,
    hidden:true,
    meta: {
      title: '共享课程平台-搜索'
    }
  },
  {
    path: '/courseTypeView/:fathertypeId',
    name: 'CourseTypeView',
    component: courseTypeView,
    //控制子组件是否加载
    meta:{
      showFooter: true,
      title: '共享课程平台-分类'
    },
  },
  {
    path: '/learn/:courseId',
    name: 'LearnView',
    component: learnView,
    meta: {
      title: '共享课程平台-学习'
    }
  },
  {
    path: '/learn',
    name: 'LearnView',
    component: learnView,
    meta: {
      title: '共享课程平台-学习'
    },
    children: [
      {
        path: '/learn/announce/:courseId',
        name: 'AnnounceView',
        component: announceView,
        meta: {
          title: '共享课程平台-学习-公告'
        }
      },
      {
        path: '/learn/content/:courseId',
        name: 'ContentView',
        component: ContentView,
        meta: {
          title: '共享课程平台-学习-课件'
        }
      },
      {
        path: '/learn/content/:courseId/:chapterId/:lessonId',
        name: 'ContentView',
        component: ContentView,
        meta: {
          title: '共享课程平台-学习-课件'
        }
      },
      {
        path:'/learn/testList/:courseId',
        name:'TestListView',
        component: testListView,
        meta: {
          title: '共享课程平台-学习-作业'
        }
      },
      {
        path:'/learn/testList/:courseId/:chapterId/:taskId',
        name:'TestListView',
        component: testListView,
        meta: {
          title: '共享课程平台-学习-作业'
        }
      },
      {
        path: '/learn/forumindex/:courseId',
        name: 'ForumindexView',
        component: forumindexView,
        meta: {
          title: '共享课程平台-学习-讨论'
        }
      },
      {
        path: '/learn/forumindex/:courseId/:discussId',
        name: 'ForumindexView',
        component: forumindexView,
        meta: {
          title: '共享课程平台-学习-讨论'
        }
      },
    ]
  },
  {
    path: '/courseEditList',
    name: 'CourseEditListView',
    component: courseEditListView,
    meta: {
      title: '共享课程平台-授课-课程列表'
    },
    children:[

    ]
  },
  {
    path: '/addCourse',
    name:'AddCourseView',
    component: addCourseView,
    meta: {
      title: '共享课程平台-授课-添加课程'
    },
  },
  {
    path: '/courseHomeEdit/:courseId',
    name:'CourseHomeEditView',
    component: CourseHomeEditView,
    meta: {
      title: '共享课程平台-授课-课程展示'
    },
  },
  {
    path: '/learnEdit/:courseId',
    name:'LearnEditView',
    component: CourseEditView,
    meta: {
      title: '共享课程平台-授课详细'
    },
  },
  {
    path: '/learnEdit',
    name: 'LearnEditView',
    component: learnEditView,
    meta: {
      title: '共享课程平台-授课详细'
    },
    children: [
      {
        path: '/learnEdit/announceEdit/:courseId',
        name: 'AnnounceEditView',
        component: announceEditView,
        meta: {
          title: '共享课程平台-授课详细-公告'
        },
      },
      {
        path: '/learnEdit/contentEdit/:courseId',
        name: 'ContentEditView',
        component: ContentEditView,
        meta: {
          title: '共享课程平台-授课详细-课件'
        },
      },
      {
        path: '/learnEdit/contentEdit/:courseId/:chapterId/:lessonId',
        name: 'ContentEditView',
        component: ContentEditView,
        meta: {
          title: '共享课程平台-授课详细-课件'
        },
      },
      {
        path:'/learnEdit/testListEdit/:courseId',
        name:'TestListEditView',
        component: testListEditView,
        meta: {
          title: '共享课程平台-授课详细-作业'
        },
      },
      {
        path:'/learnEdit/testListEdit/:courseId/:chapterId/:taskId',
        name:'TestListEditView',
        component: testListEditView,
        meta: {
          title: '共享课程平台-授课详细-作业'
        },
      },
      {
        path: '/learnEdit/forumindexEdit/:courseId',
        name: 'ForumindexEditView',
        component: forumindexEditView,
        meta: {
          title: '共享课程平台-授课详细-讨论'
        },
      },
      {
        path: '/learnEdit/forumindexEdit/:courseId/:discussId',
        name: 'ForumindexEditView',
        component: forumindexEditView,
        meta: {
          title: '共享课程平台-授课详细-讨论'
        },
      },
      {
        path: '/learnEdit/testScoring/:courseId/:chapterId/:taskId',
        name: 'TestScoringView',
        component: testScoringView,
        meta: {
          title: '共享课程平台-授课详细-批改作业'
        },
      },
      {
        path: '/learnEdit/testScoring/:courseId/:chapterId/:taskId/:userId',
        name: 'TestScoringView',
        component: testScoringView,
        meta: {
          title: '共享课程平台-授课详细-批改作业'
        },
      },
    ]
  },
  {
    path: '/userHome',
    name: 'UserHomeView',
    component: UserHomeView,
    meta: {
      title: '共享课程平台-我的主页'
    },
  },
  {
    path: '/userHome/:userId',
    name: 'UserHomeView',
    component: UserHomeView,
    meta: {
      title: '共享课程平台-用户主页'
    },
  },
  // {
  //   path:'/demoWangEditor',
  //   name: 'DemoWangEditor',
  //   component: demoWangEditor
  // },
  {
    path: '/courseTypeView',
    name: 'CourseTypeView',
    component: courseTypeView,
    meta: {
      title: '共享课程平台-分类'
    },
    children:[
      {
        path:'courseView/:courseId',
        name:'CourseView',
        component: CourseView,
        meta: {
          showFooter: false,
          title: '共享课程平台-分类'
        }
      },
      {
        path: 'courseListView/:fathertypeId/:coursetypeId',
        name:'CourseListView',
        component: courseListView,
        meta: {
          title: '共享课程平台-分类'
        },
      },
      // {
      //   path: 'demo',
      //   name: 'Demo',
      //   component: demo
      // },
    ]
  }
]

const router = new VueRouter({
  routes
})

//前置路由守卫
router.beforeEach(async(to, form, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = '共享课程平台' //此处写默认的title
  }
  next()
})

export default router
